var app = getApp()
var template = require('../../../../template/backstageTemplate.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    zid: '',
    docorder: [{
        "title": '待接诊',
        'num': 1
      },
      {
        "title": '咨询中',
        'num': 1
      },
      {
        "title": '已回复',
        'num': 1
      },
      {
        "title": '已结束',
        'num': 1
      },
      {
        "title": '已退回',
        'num': 1
      },
    ],
    order1: [{
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/fuwu1.png?sign=976e798e43db1d1dc8b398dcbb2f133c&t=1591152481',
        'title': '挂号',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/fuwu2.png?sign=cda98d6f4e7f0ee71b1e423f8493a2e3&t=1591152498',
        'title': '解读',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/fuwu3.png?sign=cd5d516be2c0370bc203f16058438ac9&t=1591152506',
        'title': '医生卡',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/fuwu4.png?sign=8f02c9a97981def329d971f885f98f23&t=1591152514',
        'title': '手术安排',
        'url': ''
      },
    ],
    order2: [{
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/guanli1.png?sign=120cb4412aa5f31d26da92ebce67c512&t=1591152458',
        'title': '签约患者',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/guanli2.png?sign=c658b5e3bfb8d33f41ebb62295031360&t=1591152467',
        'title': '普通患者',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/guanli3.png?sign=38fa099837b1c985ee8f225a75ef5abc&t=1591152447',
        'title': '年卡患者',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/guanli3.png?sign=38fa099837b1c985ee8f225a75ef5abc&t=1591152447',
        'title': '手术患者',
        'url': ''
      },
      {
        "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/guanli4.png?sign=583fbf8bd077e457663cd5bd7018d5b4&t=1591152435',
        'title': '患者分组',
        'url': ''
      },
    ],
    // order3: [
    //   {
    //     "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/zhuansu1.png?sign=50db551e6932f397c33fbc9ae837c672&t=1591165046',
    //     'title': '资金中心',
    //     'url': '/hyb_yl/mysubpages/pages/capitacenter/capitacenter'
    //   },
    //   // {
    //   //   "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/zhuansu2.png?sign=8a96eea9c68ebf89d3eaab1d98a4ff4b&t=1591165077',
    //   //   'title': '患者会话',
    //   //   'url': ''
    //   // },
    //   // {
    //   //   "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/zhuansu3.png?sign=13816921a0d4fd58a0c5416d9a14842b&t=1591165089',
    //   //   'title': '患教',
    //   //   'url': ''
    //   // },
    //   {
    //     "icon": 'https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/%E6%96%B0%E7%89%88%E5%8C%BB%E7%96%97icon/zhuansu4.png?sign=b2251e27c79906338be6498d2a45739f&t=1591165175',
    //     'title': '开通服务',
    //     'url': '/hyb_yl/mysubpages/pages/openservice/openservice'
    //   },
    // ],
    windowWidth: 0,
    windowHeight: 0,
    t_status: false,
    isopera: false,
  },
  docterorder: function (e) {
    // console.log(e);
    const state = e.currentTarget.dataset.dex;
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/docorder/docorder?state=' + state,
    })
  },
  patientman: function (e) {
    const state = e.currentTarget.dataset.dex;
    var zid = e.currentTarget.dataset.zid;
    // if (state == 3) {
    //   wx.navigateTo({
    //     url: '/hyb_yl/mysubpages/pages/patientgroup/patientgroup?zid=' + zid,
    //   })
    // } else {
    if(state == '4')
    {
      wx.navigateTo({
        url: '/hyb_yl/krecovery/pages/patient_list/patient_list?zid='+zid,
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/patientman/patientman?state=' + state + '&zid=' + zid,
      })
    }
    
    // }
  },
  fenzu_page: function (e) {
    var zid = e.currentTarget.dataset.zid;
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/grouping_list/grouping_list?zid=' + zid,
    })
  },
  saveImage: function (e) {
    let url = e.currentTarget.dataset.url;
    console.log(e);
    wx.getImageInfo({
      src: url,
      success: (res) => {
        let path = res.path;
        wx.saveImageToPhotosAlbum({
          filePath: path,
          success(res) {
            console.log(res);
          },
          fail: (res) => {
            console.log(res);
          }
        })
      },
      fail: (res) => {
        console.log(res);
      }
    })

  },
  zsservice: function (e) {
    var that = this
    const url = e.currentTarget.dataset.url;
    var zid = that.data.zid
    console.log(e)
    wx.navigateTo({
      url: url + '?zid=' + zid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    template.tabbar("tabBar", 0, this)
    var that = this

    //执行号码绑定


    app.util.request({
      'url': 'entry/wxapp/index.base',
      success: function (res) {
        console.log(res)
        that.setData({
          base: res.data
        })
      }
    })
  

    var bgc = wx.getStorageSync('color')
    this.setData({
      bg_color: bgc
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.sharecon();
    app.util.request({
      'url': "entry/wxapp/user.getcenter",
      data: {
        type: 1
      },
      success: function (res) {
        that.setData({
          server: res.data
        })
      }
    })
  },
  ishaibao: function () {
    var that = this
    var zid = that.data.zid
    //生成二维码
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.docerweimainfo',
      data: {
        zid: zid,
      },
      success: function (res) {
        console.log(res)
        var weweima = res.data.weweima
        that.setData({
          weweima: weweima
        })
        var info = JSON.stringify(res.data)

      },
    })
    this.setData({
      isopera: true
    })
    this.sharecon();
  },
  closeshare: function () {
    this.setData({
      isopera: false
    })
  },
  sharecon: function () {
    var that = this;
    // var hb = that.data.hbbg;
    // var ewm = that.data.ewm;
    var avatarurl_width = 100; //绘制的头像宽度
    var avatarurl_heigth = 100; //绘制的头像高度
    var avatarurl_x = 50; //绘制的头像在画布上的位置
    var avatarurl_y = 50; //绘制的头像在画布上的位置
    that.setData({
      t_status: true
    })

    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowWidth: res.screenWidth,
          windowHeight: res.screenHeight
        })
      },
    });
  },

  operation: function () {
    var that = this;
    wx.canvasToTempFilePath({
      x: 0,
      y: 0,
      canvasId: "canvass",
      success: function (ress) {
        console.log(ress);
        wx.saveImageToPhotosAlbum({
          filePath: ress.tempFilePath,
          success: function (res) {
            wx.showToast({
              title: '保存成功',
            });
            setTimeout(function () {
              that.setData({
                t_status: false,
                isopera: false
              })
            }, 1000)
          },
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDocinfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getDocinfo(e) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/studio.ifzhuanjia',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        var zid = res.data.zid
        wx.setStorageSync('zid', zid)
        var z_telephone = res.data.z_telephone
        that.setData({
          docinfo: res.data,
          zid: res.data.zid,
          data_list: res.data.data_list,
          z_telephone: res.data.z_telephone,
          weweima: res.data.weweima,
          advertisement: res.data.advertisement
        })
        that.bangdingtel(zid, z_telephone)
      }
    })
  },
  getDoc() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/studio.ifzj',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        if (res.data == 1) {
          wx.setStorage({
            key: 'userinfotype',
            data: 'doc',
          })
        }
      }
    })
  },
  goBacks: function (e) {
    var title = e.currentTarget.dataset.title;
    var keyword = e.currentTarget.dataset.keyword;
    var zid = this.data.zid;
    wx.navigateTo({
      url: '/hyb_yl/lvtongserver/pages/docorder/docorder?title=' + title + '&keyword=' + keyword + '&zid=' + zid + '&doc=1',
    })
  },
  qiandan: function (e) {
    var title = e.currentTarget.dataset.title;
    var keyword = e.currentTarget.dataset.keyword;
    wx.navigateTo({
      url: '/hyb_yl/lvtongserver/pages/docorder/docorder?title=' + title + '&keyword=' + keyword + '&zid=&doc=1',
    })
  },
  goExplanation: function () {
    var that = this;
    var zid = that.data.zid
    var sate = 1
    wx.setStorageSync('sate', sate)
    wx.navigateTo({
      url: "/hyb_yl/backstageFollowUp/pages/explanation/explanation?zid=" + zid,
      success: function () {
        that.setData({
          nonReadBoo: !0
        });
      }
    });
  },
  hzwenzhen(e) {
    var that = this
    console.log(e)
    var titlme = e.currentTarget.dataset.titlme
    var key_words = e.currentTarget.dataset.key_words
    var id = e.currentTarget.dataset.id
    var zid = that.data.zid
    var z_telephone = that.data.z_telephone
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/docorder/docorder?titlme=' + titlme + '&key_words=' + key_words + '&id=' + id + '&zid=' + zid + '&z_telephone=' + z_telephone,
    })
  },
  goBack: function (e) {
    var that = this
    console.log(e)
    var titlme = e.currentTarget.dataset.titlme
    var key_words = e.currentTarget.dataset.key_words
    var id = e.currentTarget.dataset.id
    var zid = that.data.zid


    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/serviceList/serviceList?titlme=' + titlme + '&key_words=' + key_words + '&id=' + id + '&zid=' + zid,
    })
  },
  bangdingtel(zid, z_telephone) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/yuyue.telcotime',
      data: {
        doc_phone: that.data.z_telephone,
        zid: that.data.zid
      },
      success: function (res) {
        console.log(res, privateNum)
        //更新聊天电话
        if (res.data !== 1) {
          if (res.data.privateNum == undefined || res.data.privateNum == 'undefined') {
            var privateNum = ''
          } else {
            var privateNum = res.data.privateNum
          }
          app.util.request({
            url: 'entry/wxapp/yuyue.upcharmsg',
            data: {
              zid: that.data.zid,
              privateNum: privateNum
            },
            success: function (res) {
              console.log(res)
            }
          })
        }

      }
    })
  },
  // 术后服务包跳转
  shtype:function(){
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/edit_recovery/edit_recovery?zid='+that.data.zid,
    })
  },
})